$(function() {
    //初始化
    Begin();
})
////////////--------------消息统计--------------------////////////
$.ajax({
    type: "post",
    url: "/msgStatistic/getMsgStatisticById",
    data:{token:sessionStorage.token},
    async: true,
    success: function(data) {
    	$('#byxx').html(data.resultData.byxx);
    	$('#bzxx').html(data.resultData.bzxx);
    	$('#jrxx').html(data.resultData.jrxx);
    	$('#xxzl').html(data.resultData.xxzl);
    }
});



////////////--------------统计图表--------------------////////////
var xAxisData = [],
    yAxisData = [],
    option,
    tabFirstClick;

//日统计
$.ajax({
    type: "post",
    url: "/msgStatistic/getMsgStatisticDaily",
    data:{token:sessionStorage.token},
    async: true,
    success: function(data) {
        var echartFirst = echarts.init(document.getElementById('chartFirst'));
        for(var i = 0; i < data.resultData.list.length; i++) {
            xAxisData.push(i);            
            yAxisData.push(data.resultData.list[i]);
        }
        EchartOption(echartFirst);
    }
});

var chartTab = new Vue({
    el: "#chartTab",
    data: function() {
        return {
        	/*options: [{
                value: '选项1',
                label: '内容1'
              }],*/
        	
        	options: [],
            value: '',
            activeName: 'chartFirst'
        }
    },
    created: function () {
    	$.ajax({
            type: "post",
            url: "/msgStatistic/getDepartById",
            data:{token:sessionStorage.token},
            async: true,
            success: function(data) {
            	for(var i = 0; i < data.resultData.rows.length; i++) {
            		chartTab.options.push({
                        //key: data.resultData.rows[i].key,
                        label: data.resultData.rows[i].orgName,//名称
                        value: data.resultData.rows[i].orgCode//编号
                        //show: data.resultData.rows[i].state,
                        //checkOnly: data.resultData.rows[i].checkOnly
                    });
            	}            	
            }
        });
    },
    methods: {    	
    	changeValue:function(value){    		
    		$('#orgCode').val(value);
    		//$($('.el-tabs__item')[0]).click();
    		 $.ajax({
             	type: "post",
             	url: "/msgStatistic/getMsgStatisticDaily",
             	data:{token:sessionStorage.token,orgCode:value},  
                 async: true,
                 success: function(data) {
                	 xAxisData.splice(0,xAxisData.length);
                     yAxisData.splice(0,yAxisData.length);
                     var echartFirst = echarts.init(document.getElementById('chartFirst'));
                     for(var i = 0; i < data.resultData.list.length; i++) {
                         xAxisData.push(i);
                         yAxisData.push(data.resultData.list[i]);
                     }
                     EchartOption(echartSecond);
                 }
             });
    	},
    	changeValue2:function(value){    		
    		$('#orgCode').val(value);
    		//$($('.el-tabs__item')[1]).click();
    		 $.ajax({
                 type: "post",
                 url: "/msgStatistic/getMsgStatisticMonth",
                 data:{token:sessionStorage.token,orgCode:value},  
                 async: true,
                 success: function(data) {
                	 xAxisData.splice(0,xAxisData.length);
                     yAxisData.splice(0,yAxisData.length);
                     var echartSecond = echarts.init(document.getElementById('chartSecond'));
                     for(var i = 0; i < data.resultData.list.length; i++) {
                         xAxisData.push(i+1);
                         yAxisData.push(data.resultData.list[i+1]);
                     }
                     EchartOption(echartSecond);
                 }
             });
    	},
    	changeValue3:function(value){    		
    		$('#orgCode').val(value);
    		//$($('.el-tabs__item')[2]).click();
    		 $.ajax({
                 type: "post",
                 url: "/msgStatistic/getMsgStatisticYear",
                 data:{token:sessionStorage.token,orgCode:value},         
                 async: true,
                 success: function(data) {
                	 xAxisData.splice(0,xAxisData.length);
                     yAxisData.splice(0,yAxisData.length);
                     var echartThird = echarts.init(document.getElementById('chartThird'));
                     for(var i = 0; i < data.resultData.list.length; i++) {
                         xAxisData.push(i+1);
                         yAxisData.push(data.resultData.list[i+1]);
                     }
                     EchartOption(echartThird);
                 }
             });
    		
    	},
        handleClick:function(tab, event) {    		
            //tab点击是否加载
            if(tab.index == tabFirstClick) {
                return;
            } else {
                xAxisData = [];
                yAxisData = [];
                tabFirstClick = tab.index;
            }
            if(tab.index == 0) {
                $.ajax({
                	type: "post",
                	url: "/msgStatistic/getMsgStatisticDaily",
                    data:{token:sessionStorage.token},
                    async: true,
                    success: function(data) {
                        var echartFirst = echarts.init(document.getElementById('chartFirst'));
                        for(var i = 0; i < data.resultData.list.length; i++) {
                            xAxisData.push(i);
                            yAxisData.push(data.resultData.list[i]);
                        }
                        EchartOption(echartSecond);
                    }
                });
            }
            if(tab.index == 1) {
                $.ajax({
                    type: "post",
                    url: "/msgStatistic/getMsgStatisticMonth",
                    data:{token:sessionStorage.token},
                    async: true,
                    success: function(data) {
                        var echartSecond = echarts.init(document.getElementById('chartSecond'));
                        for(var i = 0; i < data.resultData.list.length; i++) {
                            xAxisData.push(i+1);
                            yAxisData.push(data.resultData.list[i+1]);
                        }
                        EchartOption(echartSecond);
                    }
                });
            }
            if(tab.index == 2) {
                $.ajax({
                    type: "post",
                    url: "/msgStatistic/getMsgStatisticYear",
                    data:{token:sessionStorage.token},
                    async: true,
                    success: function(data) {
                        var echartThird = echarts.init(document.getElementById('chartThird'));
                        for(var i = 0; i < data.resultData.list.length; i++) {
                            xAxisData.push(i+1);
                            yAxisData.push(data.resultData.list[i+1]);
                        }
                        EchartOption(echartThird);
                    }
                });
            }
        }
    }
})

function EchartOption(obj) {
    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'line',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },        
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        color: ['#c6f5e5'],
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            data: xAxisData
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
            name: '消息数量',
            type: 'line',
            areaStyle: {
                normal: {}
            },
            data: yAxisData
        }]
    };
    //每次窗口大小改变的时候都会触发onresize事件，这个时候我们将echarts对象的尺寸赋值给窗口的大小这个属性，从而实现图表对象与窗口对象的尺寸一致的情况
    window.onresize = obj.resize;
    obj.setOption(option);
}

//初始化
function Begin() {
    //面包屑
    new Vue().$mount('#crumbs');
    //获取整个菜单
    //new Vue().$mount('#menuL');
    //消息统计模块
    new Vue().$mount('#app');
    //饼图
    /*new Vue().$mount('#chartContent');*/
    //左菜单滚动
    var oTop = $(".vany_authority").offset().top + 14;
    var sTop = 0;
    $(".vany_authority").scroll(function() {
        sTop = $(this).scrollTop();
        if(sTop >= oTop) {
            $("#menuL").css({
                "position": "fixed",
                "top": "60px"
            });
        } else {
            $("#menuL").css({
                "position": "absolute",
                "top": "0"
            });
        }
    });
    sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}
